import operate from '@dfeidao/atom-nodejs/db/operate';
import log from '@dfeidao/atom-nodejs/logger/log';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import { systemid } from '../../atom/config';
interface Message {
	train_number: string;
	name_training_material: string;
	address_training_material: string;
}




// 表名	train_material
// 标题	培训资料
// 字段名称	字段标题	字段类型	字段长度	是否为空	是否主键
// _id	id	string	50	ⅹ	√
// productid	产品ID	string	50	√	ⅹ
// train_number	培训编号	string	64	√	ⅹ
// name_training_material	培训资料名称	string	64	√	ⅹ
// address_training_material	培训资料地址	document	64	√	ⅹ


export default async function atom(msg: Message, action_id: string, session_id: string) {
	log(`Service begin`);
	const { result } = await await doc_code(action_id, session_id, systemid, 'BM0014260', '', 1);
	const { exec, update } = operate(action_id, session_id, systemid);
	if (result.length > 0) {
		update('train_material', { 'train_number': msg.train_number },
			{

				'name_training_material': msg.name_training_material,
				'address_training_material': msg.address_training_material

			});
	}
	const res = await exec();
	log(`Service end`);
	return res;
}
